<?php

class Db_Tables2_BContractSkuService
{
	function __construct() {
		$this->dealers_db = Zend_Registry::get("dealers_db");
	}
	
	function GetServiceStr($cs_id_arr, $type=null) //type 格式化用
	{
		$result = array(
			"str" => array(),
			"arr" => array()
		);
		
		$select = $this->dealers_db->select();
		$select->from("b_contract_sku_service", array("cs_id", "service_id", "service_name", "start_date", "expired_date"));
		$select->where("cs_id IN (?)", $cs_id_arr);
		$data = $this->dealers_db->fetchAll($select);
		
		if(!empty($data))
		{
			foreach($data as $d)
			{
				if(!isset($result["arr"][$d['cs_id']]))
				{
					$result["arr"][$d['cs_id']] = array();
				}
				
				if(1 == $type)
				{
					$result["arr"][$d['cs_id']][$d['service_id']] = array(
						"service_name" => $d['service_name'],
						"start_date" => $d['start_date'],
						"expired_date" => $d['expired_date']
					);
				}else{
					$result["arr"][$d['cs_id']][$d['service_id']] = $d['service_name']." [".$d['start_date']."至".$d['expired_date']."]";
				}
			}
			
			if(!$type)
			{
				foreach($result["arr"] as $cs_id => $service_info)
				{
					$result["str"][$cs_id] = implode("<br>", $service_info);
				}
			}
		}
		
		return $result;
	}
}